package com.googlecode.hyakutaded.pubsub;

import java.util.HashSet;
import java.util.Set;

import com.googlecode.hyakutaded.Client;
import com.googlecode.hyakutaded.json.JSONException;
import com.googlecode.hyakutaded.json.JSONObject;

public class Topic {
	private Set<Client> clients = new HashSet<Client>();
	private String name;

	public Topic(String name) {
		this.name = name;
	}

	public void addClient(Client c) {
		clients.add(c);
	}

	public void removeClient(Client c) {
		clients.remove(c);
	}

	public void set(JSONObject value) throws JSONException {
		for (Client c : clients) {
			c.set(name, value);
		}
	}

	public void add(JSONObject value) throws JSONException {
		for (Client c : clients) {
			c.add(name, value);
		}
	}

	public void update(String key, JSONObject value) throws JSONException {
		for (Client c : clients) {
			c.update(name, key, value);
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}
